subjects = {
%     'RSRC001',...
%     'RSRC002',...
%     'RSRC003',...
%     'RSRC004',...
%     'RSRC005',...
%     'RSRC006',...
%     'RSRC007',...
% % new instructions began here
%     'RSRC008',...
%     'RSRC009',...
%     'RSRC010',...
%     'RSRC011',...
%     'RSRC012',...
%     'RSRC013',...
% % faster presentation (1000ms) began here
%     'RSRC014',...
%     'RSRC015',...
%     'RSRC016',...
%     'RSRC017',...
%     'RSRC018',...
%     'RSRC019',...
%     'RSRC020',...
% eeg testing begins here
    'RSRC021'...
    'RSRC022'...
    'RSRC023'...
    'RSRC024'...
    'RSRC025'...
    'RSRC026'...
    'RSRC027'...
    'RSRC028'...
    'RSRC029'...
    'RSRC030'...
    'RSRC031'...
    'RSRC032'...
    'RSRC033'...
    'RSRC034'...
    'RSRC035'...
    'RSRC036'...
    'RSRC037'...
    'RSRC038'...
    'RSRC039'...
    'RSRC040'...
    'RSRC041'...
    'RSRC042'...
    'RSRC043'...
    'RSRC044'...
    'RSRC045'...
    'RSRC046'...
    'RSRC048'...
    'RSRC049'...
    'RSRC050'...
    'RSRC051'...
    'RSRC052'...
    'RSRC053'...
    'RSRC054'...
    'RSRC055'...
    'RSRC056'...
    'RSRC057'...
    'RSRC058'...
    'RSRC059'...
           };
%    'RSRC047'... % bad subject

sessions = {'session_0'};

uname = getenv('USER');
uroot = getenv('HOME');
dataroot = fullfile(uroot,'data/RSRC/behavioral');
saveDir = dataroot;
% saveDir = fullfile(dataroot,'events');
% if ~exist(saveDir,'dir')
%   mkdir(saveDir);
% end

eventsOutfile = fullfile(saveDir,'rsrc_events.mat');

if ~lockFile(eventsOutfile)
  error('%s already exists! Not continuing!\n',eventsOutfile);
end

combinedEvents = [];

for sub = 1:length(subjects)
  fprintf('Getting data for %s...',subjects{sub});
  for ses = 1:length(sessions)
    fprintf('%s...',sessions{ses});
    
    % set the subject events directory
    eventsDir_sub = fullfile(dataroot,subjects{sub},sessions{ses},'events');
    events = loadEvents(fullfile(eventsDir_sub,'events.mat'));
    
    % concatenate every subject's events
    combinedEvents = [combinedEvents;events];
  end
  fprintf('Done.\n');
end

fprintf('Saving %d subjects in %s...',length(subjects),eventsOutfile);
% save all subs
saveEvents(combinedEvents,eventsOutfile);
% release the lockFile
releaseFile(eventsOutfile);
fprintf('Done.\n');

% % fix event fields
% for sub = 1:length(subjects)
%   fprintf('Getting data for %s...',subjects{sub});
%   for ses = 1:length(sessions)
%     fprintf('%s...',sessions{ses});
    
%     events = rsrc_fixEvents(dataroot,subjects{sub},sessions{ses});
    
%     saveEvents(events,fullfile(dataroot,subjects{sub},sessions{ses},'events','events.mat'));
    
%   end
%   fprintf('Done.\n');
% end
